// pages/personal/exerecord.js
var util = require('../../utils/util');
var that;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    arrow:'../../images/arrow-right.png',
    logList:[],
    totalCnt:0,
    time:'',
    pageIndex:1,
    limit:10,
    hasMoreData: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that = this;
    that.setData({ time: util.formatDate(new Date(),'yyyy-MM').replace('-','年')+'月'})
    util.sendRequest('WxGetExEcLogList', { page: that.data.pageIndex, limit:that.data.limit},function(resp){
      for (var i = 0; i < resp.result.list.length ; i ++ ){
        resp.result.list[i].date = resp.result.list[i].createTime.split(' ')[0];
        resp.result.list[i].time = resp.result.list[i].createTime.split(' ')[1];
      }
      that.setData({ logList: resp.result.list, totalCnt: resp.result.total, pageIndex: (that.data.pageIndex + 1), hasMoreData: resp.result.list.length<that.data.limit?false:true});
    },'加载中...',function(){

    });
  },
  detail:function(e){
    var id = e.currentTarget.dataset.objid;
    wx.setStorageSync('objid', id);
    wx.navigateTo({
      url: '/pages/personal/detailrecord',
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    that.setData({ logList: [], totalCnt: 0, pageIndex: 1, hasMoreData: true });
    that.onLoad();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (that.data.hasMoreData) {
      util.sendRequest('WxGetExEcLogList', { page: that.data.pageIndex, limit: that.data.limit }, function (resp) {
       
        var list = that.data.logList;
        for (var i = 0; i < resp.result.list.length ;i++){
          resp.result.list[i].date = resp.result.list[i].createTime.split(' ')[0];
          resp.result.list[i].time = resp.result.list[i].createTime.split(' ')[1];
          list.push(resp.result.list[i]);
        }
        that.setData({ logList: list, totalCnt: resp.result.total, pageIndex: (that.data.pageIndex + 1), hasMoreData: resp.result.list.length < that.data.limit ? false : true });
      }, '加载中...', function () {

      });
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
      return util.getShareMsg();
  }
})